import AccessToken from '../db/mongo/AccessToken'

class AccessTokenService {
  /* 存储AccessToken信息 */
  async setAccessToken(accessToken, expireTime) {
    return await AccessToken.create({ accessToken, expireTime })
  }

  /* 获取AccessToken信息 */
  async getAccessToken() {
    return await AccessToken.findOne()
  }

  /* 重置存储AccessToken信息过期时间 */
  async resetAccessToken(key, expire) {
    try {
      const res = await AccessToken.resetExpirationTime(key, expire)
      console.log('测试重置:', res)
    } catch (error) {
      console.log('测试error:', error)
    }
  }

  /* 移除存储的AccessToken信息 */
  async removeAccessToken(key) {
    try {
      const res = await AccessToken.removeData(key)
      console.log('测试移除:', res)
    } catch (error) {
      console.log('测试error:', error)
    }
  }
}
export default new AccessTokenService()
